home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / SETBLOCK.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  798 b   |  33 lines

  1. /* SETBLOCK.C --- p. 658 */
  2. #include <stdio.h>
  3. #include <dos.h>
  4. #include <mem.h>
  5. #define DOS_PRTSTR  9
  6. char str[80] = "Test allocmem...\n$";
  7. main()
  8. {
  9.     union REGS xr;
  10.     struct SREGS sr;
  11.     char far *stradd;
  12.     unsigned int segadd, maxsize;
  13.     stradd = (char far *)(&str[0]);
  14.     if(allocmem(1, &segadd) != -1)
  15.     {
  16.         printf("Memory allocation failed!\n");
  17.         exit(0);
  18.     }
  19.     if((maxsize = setblock(segadd, 5)) == -1)
  20.     {
  21.         printf("setblock failed!\n");
  22.         printf("Maximum size possible = %d paragraphs\n", maxsize);
  23.         exit(0);
  24.     }
  25.         /* Use movedata to copy the string to allocated memory */
  26.     movedata(FP_SEG(stradd), FP_OFF(stradd), segadd, 0, 80);
  27.     sr.ds = segadd;
  28.     xr.x.dx = 0;
  29.     xr.h.ah = DOS_PRTSTR;
  30.     intdosx(&xr, &xr, &sr);
  31.                     /* Free memory before exiting */
  32.     freemem(segadd);
  33. }